﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace DHJ.Cost.CostBooking.Config
{
    public static class CostConfigProvider
    {
        public static List<CostType> GetAllCostTypes()
        {
            var configs = from type in Assembly.GetExecutingAssembly().GetTypes()
                    .Where(t => t.BaseType == typeof(CostConfig))
                          select Activator.CreateInstance(type) as CostConfig;
            return (from config in configs
                   orderby config.Index
                   from child in config.Children
                   select new CostType(child.Category, child.Title)).ToList();
        }
    }

    public class CostType
    {
        public CostType(string category, string title)
        {
            Category = category;
            Title = title;
        }
        public string Category { get; set; }
        public string Title { get; set; }
    }
}